home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-16 | 4.0 KB | 167 lines | [TEXT/MMCC] |
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- //
- // Horrible Rickety Shell, by Dave Johnson
- //
- // © Copyright 1985 - 1995 Anyone Who Wants It,
- // All Rights Energetically Hurled as far away from me as possible.
- // Use at your own (considerable) risk.
-
-
- #include "Shell.h"
- #include "DialogUtils.h"
-
- Boolean gDoneFlag = false;
- Rect gDeskRect;
- MenuHandle gShellMenuHandles[kNumShellMenus];
- unsigned long gClickTime, gSleepTime = 0;
- short gDocTitleHeight, gDocFrameWidth; // Window Stats, for use in positioning
-
- // UPPs
- AEEventHandlerUPP gOAPPHandlerUPP, gODOCHandlerUPP, gPDOCHandlerUPP, gQUITHandlerUPP;
- ControlActionUPP gScrollActionUPP;
-
- void main (void)
- {
- EventRecord theEvent;
- CursHandle curs;
-
- FlushEvents (everyEvent - diskMask, 0 );
-
- // Generic heap initialization.
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters();
-
- // Start up the toolbox so we can notify people if there's a problem
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- // Set cursor to watch
- curs = GetCursor(watchCursor);
- SetCursor(*curs);
-
- // Try to start up shell
- if(InitShell() == true)
- {
- // Set cursor back to arrow
- SetCursor(&qd.arrow);
-
- // Loop forever
- while(gDoneFlag == false)
- {
- WaitNextEvent(everyEvent, &theEvent, gSleepTime, nil);
- DoEvent(&theEvent);
- }
- }
-
- BailOut();
- }
-
- /*-------------------------------------------------------------------------
- initshell() Inits all the application-specific variables...
- -------------------------------------------------------------------------*/
-
- Boolean InitShell(void)
- {
- MenuHandle mhndl;
- unsigned long seed;
- OSErr err;
-
- // Check for the machine characteristics we need to run
- if(CheckMachine() == false)
- {
- DoErrorAlert(kWimpyMachineStr, 0);
- return false;
- }
-
- // Check for GX
- if(CheckQuickDrawGX() == false)
- {
- DoErrorAlert(kNoGXStr, 0);
- return false;
- }
-
- // ----------------------------------------------------------------
- // Make upps in the app heap - no need to dispose them at the end.
-
- // Scroll action UPP
- gScrollActionUPP = NewControlActionProc(ScrollActionProc);
-
- // Install the required Apple Event Handlers
- gOAPPHandlerUPP = NewAEEventHandlerProc(OAPPHandler);
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOAPPHandlerUPP, 0, FALSE);
- if(err != noErr)
- return false;
- gODOCHandlerUPP = NewAEEventHandlerProc(ODOCHandler);
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gODOCHandlerUPP, 0, FALSE);
- if(err != noErr)
- return false;
- gPDOCHandlerUPP = NewAEEventHandlerProc(PDOCHandler);
- err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gPDOCHandlerUPP, 0, FALSE);
- if(err != noErr)
- return false;
- gQUITHandlerUPP = NewAEEventHandlerProc(QUITHandler);
- err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gQUITHandlerUPP, 0, FALSE);
- if(err != noErr)
- return false;
-
- // Build the dialog UPPs
- InitDialogUPPs();
-
- // Set up GX stuff
- if(SetUpGX() == false)
- {
- DoErrorAlert(kNoMemStr, 0);
- return false;
- }
-
- // Get the window measurements we'll need later
- CalcWindowStats();
-
- // Get Bounding box of Desktop
- gDeskRect = (**GetGrayRgn()).rgnBBox;
-
- // Reset random number generator
- GetDateTime(&seed);
- qd.randSeed = seed;
-
- // Read in menus, draw the bar...
- mhndl = GetMenu(kAppleMenuID);
- if(mhndl == nil)
- return false;
- AddResMenu(mhndl, 'DRVR');
- (*mhndl)->menuID = kAppleMenuID;
- InsertMenu(mhndl, 0);
- gShellMenuHandles[kAppleMenu] = mhndl;
-
- mhndl = GetMenu(kFileMenuID);
- if(mhndl == nil)
- return false;
- (*mhndl)->menuID = kFileMenuID;
- InsertMenu(mhndl, 0);
- gShellMenuHandles[kFileMenu] = mhndl;
-
- mhndl = GetMenu(kEditMenuID);
- if(mhndl == nil)
- return false;
- (*mhndl)->menuID = kEditMenuID;
- InsertMenu(mhndl, 0);
- gShellMenuHandles[kEditMenu] = mhndl;
-
- DrawMenuBar();
-
- // Try to Init the App's stuff
- if(AppInit() == false)
- return false;
-
- // success!
- return true;
- }
-